package thread;

/**
 * 地2种创建线程的方式：实现Runnnable接口；
 * 优点：
 * 1.不存在继承冲突的问题；
 * 2.将任务与线程分离，不存在耦合
 */
public class Demo02Thread {
    public static void main(String[] args) {
        //1.实例化任务
        Runnable r1=new MyRunnable1();
        Runnable r2=new MyRunnable2();
        //2.创建线程
        Thread t1=new Thread(r1);
        Thread t2=new Thread(r2);
        //3.启动线程
        t1.start();
        t2.start();
    }
}

class MyRunnable1 implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println("别问我是谁");
        }
    }
}

class MyRunnable2 implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println("请与我相恋");
        }
    }
}
